const webpack = require('webpack')
const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
    entry:'./src/main.js',
    output:{
        filename:'bundle.[hash:8].js',
        path :path.join(__dirname,'dist')
    },
    module:{
        rules :[
            {
                test :/\.vue$/,
                loader:'vue-loader'
            },
            {
                test :/\.js$/,
                use:{
                    loader :'babel-loader',
                    options:{
                        presets:['@babel/preset-env']
                    }
                }
            },
            {
                test:/\.(js|vue)$/,
                use:{
                    loader:'eslint-loader',
                    options:{
                        formatter :require('eslint-friendly-formatter')
                    }
                },
                enforce:'pre',
                exclude:/node_modules/,
                include:[__dirname + '/src']
            },
            {
                test :/\.css$/,
                use:['vue-style-loader','css-loader']
            },
            {
                test :/\.less$/,
                use:['style-loader','css-loader','less-loader']
            },
            {
                test:/\.(png|jpg?e|gif|svg)$/,
                use:{
                    loader :'file-loader',
                    options:{
                        name:'img/[name].[ext]'
                    }
                }
            }
        ]
    },
    plugins:[
        new webpack.DefinePlugin({
            BASE_URL:JSON.stringify('') // 生产代码片段
        }),
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title:'part2-2 homework demo',
            template:'./public/index.html'
        })
    ]
}